package com.ruoyi.web.controller.system;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.KingBdOrganization;
import com.ruoyi.system.service.IKingBdOrganizationService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 组织机构Controller
 * 
 * @author ruoyi
 * @date 2021-04-28
 */
@RestController
@RequestMapping("/system/organization")
public class KingBdOrganizationController extends BaseController
{
    @Autowired
    private IKingBdOrganizationService kingBdOrganizationService;

    /**
     * 查询组织机构列表
     */
    @PreAuthorize("@ss.hasPermi('system:organization:list')")
    @GetMapping("/list")
    public TableDataInfo list(KingBdOrganization kingBdOrganization)
    {
        startPage();
        List<KingBdOrganization> list = kingBdOrganizationService.selectKingBdOrganizationList(kingBdOrganization);
        return getDataTable(list);
    }

    /**
     * 导出组织机构列表
     */
    @PreAuthorize("@ss.hasPermi('system:organization:export')")
    @Log(title = "组织机构", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(KingBdOrganization kingBdOrganization)
    {
        List<KingBdOrganization> list = kingBdOrganizationService.selectKingBdOrganizationList(kingBdOrganization);
        ExcelUtil<KingBdOrganization> util = new ExcelUtil<KingBdOrganization>(KingBdOrganization.class);
        return util.exportExcel(list, "organization");
    }

    /**
     * 获取组织机构详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:organization:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(kingBdOrganizationService.selectKingBdOrganizationById(id));
    }

    /**
     * 新增组织机构
     */
    @PreAuthorize("@ss.hasPermi('system:organization:add')")
    @Log(title = "组织机构", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody KingBdOrganization kingBdOrganization)
    {
        return toAjax(kingBdOrganizationService.insertKingBdOrganization(kingBdOrganization));
    }

    /**
     * 修改组织机构
     */
    @PreAuthorize("@ss.hasPermi('system:organization:edit')")
    @Log(title = "组织机构", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody KingBdOrganization kingBdOrganization)
    {
        return toAjax(kingBdOrganizationService.updateKingBdOrganization(kingBdOrganization));
    }

    /**
     * 删除组织机构
     */
    @PreAuthorize("@ss.hasPermi('system:organization:remove')")
    @Log(title = "组织机构", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(kingBdOrganizationService.deleteKingBdOrganizationByIds(ids));
    }
}
